package com.example.myfirstapplication

import android.content.Intent
import android.content.IntentFilter
import android.os.Bundle
import com.example.myfirstapplication.receiver.TimeChangeReceiver
import com.example.myfirstapplication.utils.BaseActivity
import kotlinx.android.synthetic.main.activity_broadcast.*

class BroadcastActivity : BaseActivity() {
    lateinit var timeChangeReciver: TimeChangeReceiver
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_broadcast)
        val intentFilterSystemTime = IntentFilter()
        intentFilterSystemTime.addAction("android.intent.action.TIME_TICK")
        timeChangeReciver = TimeChangeReceiver()
        registerReceiver(timeChangeReciver, intentFilterSystemTime)

        btnSendMyBroadcast.setOnClickListener {
            val intent = Intent("com.example.myfirstapplication.MY_BROADCAST")
            intent.setPackage(packageName)
            sendOrderedBroadcast(intent, null)
        }
        btnSendOffLine.setOnClickListener {
            val intent = Intent("com.example.myfirstapplication.OFFLINE")
            intent.setPackage(packageName)
            sendBroadcast(intent)
        }
    }

    override fun onDestroy() {
        super.onDestroy()
    }
}